package com.enthal.basicpers

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import kotlin.concurrent.thread

/**
 * A simple [Fragment] subclass as the second destination in the navigation.
 */
class SecondFragment : Fragment() {

    override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_second, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.findViewById<Button>(R.id.button_second).setOnClickListener {
            findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment)
        }

    //    RuntimeStatus.vibrate(requireContext())
   //     RuntimeStatus.settingsNotice(requireContext())

        val isnoticeper = RuntimeStatus.notificationListenerEnable(requireContext())
        Toast.makeText(requireContext(), "Notice permission Status: $isnoticeper", Toast.LENGTH_LONG).show()
        if(!isnoticeper)
            RuntimeStatus.settingsNotice(requireContext())

    //    RuntimeStatus.sendTestNotice(requireContext())
        RuntimeStatus.sendNotice(requireContext())
        view.context.sendBroadcast(Intent("MYBR"))

        val isntrunning = RuntimeStatus.isServiceRunning(requireContext(), NoticeListenerService::class.java.name)
        Toast.makeText(requireContext(), "Notice Service Status: $isntrunning", Toast.LENGTH_LONG).show()

        RuntimeStatus.requestIgnoreBatteryOptimizations(requireContext())
        /*
        thread(start = true) {
            HttpRequest.getFilters()
        }
         */
    }
}